﻿/*  CamHelper (See http://camhelper.codeplex.com/ or https://bitbucket.org/AndiKS/camhelper for more Info)
    Copyright (C) 2011 Andreas Wimmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using CamHelper.Interpreter;
using NUnit.Framework;

namespace CamHelper.Tests.Interpreter
{
    [TestFixture]
    public class ParameterFileTest
    {
        [Test]
        public void Empty()
        {
        }

        [Test]
        public void ProcessFile()
        {
            var file = new ParameterFile("test.frm", String.Empty);
            Assert.AreEqual(ParameterFileType.ProcessFile, file.FileType);
        }

        [Test]
        public void ParameterFile()
        {
            var file = new ParameterFile("test.par", String.Empty);
            Assert.AreEqual(ParameterFileType.ParameterFile, file.FileType);
        }

        [Test]
        public void CategoryPar()
        {
            var content =
@"[Par]		// Parameters

# app_ret_ang = 20";

            var file = new ParameterFile(@"C:\Temp\test.par", content);

            Assert.AreEqual(file.FileName, "test.par");
            Assert.AreEqual(file.FullFileName, @"C:\Temp\test.par");
            Assert.AreEqual(file.Lines.Count, 3);
            Assert.AreEqual(file.PureContent, content);

            var p1 = file.Parameters[".par.app_ret_ang"];
            Assert.AreEqual(p1.Value, "20");
            Assert.AreEqual(p1.Category, "Par");
        }

        [Test]
        public void CategoryGlobal()
        {
            var content =
@"[global]

# optimization_path		 = 0";

            var file = new ParameterFile(@"C:\Temp\test.par", content);

            Assert.AreEqual(file.FileName, "test.par");
            Assert.AreEqual(file.FullFileName, @"C:\Temp\test.par");
            Assert.AreEqual(file.Lines.Count, 3);
            Assert.AreEqual(file.PureContent, content);

            var p1 = file.Parameters[".global.optimization_path"];
            Assert.AreEqual(p1.Value, "0");
            Assert.AreEqual(p1.Category, "Global");
        }

        [Test]
        public void CategoryList()
        {
            var content =
@"[global]

# optimization_path		 = 0";

            var file = new ParameterFile(@"C:\Temp\test.par", content);

            Assert.That(file.Categories.Count, Is.EqualTo(1));
            Assert.That(file.Categories[0], Is.EqualTo("Global"));
        }
    }
}
